<html>

<head>

</head>

<body>

<script type="text/javascript">

ps = 10000;
pl = 10000;
seconds_left = 10*60;

<!--
function t() {
	v = new Date();
	var bxx = document.getElementById('bxx');
	var timeout = 1;
	n=new Date();
	ss=pp;
	aa=Math.round((n.getTime()-v.getTime())/1000.);
	s=ss-aa;
	m=0;
	h=0;
	
	if ((ss + 3) < aa) {
	  bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
	  
	  if ((ss + 6) >= aa) {	    
	  	window.setTimeout('document.location.href="index.php?page=b_building&session='+ps+'&planet='+pl+'";', 3500);
  	  }
	} else {
	if(s < 0) {
	    if (1) {
			bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
			window.setTimeout('document.location.href="index.php?page=b_building&session='+ps+'&planet='+pl+'";', 2000);
		} else {
			timeout = 0;
			bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
		}
	} else {
		if(s>59){
			m=Math.floor(s/60);
			s=s-m*60;
		}
        if(m>59){
        	h=Math.floor(m/60);
        	m=m-h*60;
        }
        if(s<10){
        	s="0"+s;
        }
        if(m<10){
        	m="0"+m;
        }
        
       	bxx.innerHTML=h+":"+m+":"+s;
	}    
	pp=pp-1;
	if (timeout == 1) {
    	window.setTimeout("t();", 999);
    }
    }
}
//-->
</script>

Buggy t() timer from original OGame: <br/>

<div id="bxx"></div>

<script language=JavaScript>
	// pp - seconds before the timer expires
	pp=seconds_left;
    t();
</script>

<br/>
Reliable timer:

<!-- Display the countdown timer in an element -->
<div id="demo"></div>

<script>
var tt;

// https://www.w3schools.com/howto/howto_js_countdown.asp (modified)
function my_t()
{
	// Get today's date and time
	var now = new Date().getTime();

	// If the count down is finished, write some text
	if (now >= dpp) {
		clearInterval(tt);
		//document.getElementById("demo").innerHTML = "EXPIRED";
		return;
	}

	// Find the distance between now and the count down date (in milliseconds)
	var distance = dpp - now;

	// Time calculations for days, hours, minutes and seconds
	var ms_per_hour = 60 * 60 * 1000;
	var hours = Math.floor(distance / ms_per_hour);
	distance -= hours * ms_per_hour;

	var ms_per_minute = 60 * 1000;
	var minutes = Math.floor(distance / ms_per_minute);
	distance -= minutes * ms_per_minute;

	var seconds = Math.floor(distance / 1000);

    if(minutes < 10){
    	minutes = "0" + minutes;
    }
    if(seconds < 10){
    	seconds = "0" + seconds;
    }

	// Display the result in the element with id="demo"
	document.getElementById("demo").innerHTML = hours + ":" + minutes + ":" + seconds;
}

// Update the count down
var dpp = new Date().getTime() + (seconds_left + 1) * 1000;
tt = setInterval (my_t, 100);
</script>



<script type="text/javascript">
<!--
function t_fix() {
	v = new Date();
	var bxx = document.getElementById('bxx2');
	var timeout = 1;
	n=new Date();
	if (!('dpp' in bxx)) {
		bxx.dpp = n.getTime() + pp2 * 1000;
	}
	ss=Math.round((bxx.dpp-n.getTime())/1000.);
	aa=Math.round((n.getTime()-v.getTime())/1000.);
	s=ss-aa;
	m=0;
	h=0;
	
	if ((ss + 3) < aa) {
	  bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
	  
	  if ((ss + 6) >= aa) {	    
	  	window.setTimeout('document.location.href="index.php?page=b_building&session='+ps+'&planet='+pl+'";', 3500);
  	  }
	} else {
	if(s < 0) {
	    if (1) {
			bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
			window.setTimeout('document.location.href="index.php?page=b_building&session='+ps+'&planet='+pl+'";', 2000);
		} else {
			timeout = 0;
			bxx.innerHTML="Окончено<br>"+"<a href=index.php?page=b_building&session="+ps+"&planet="+pl+">Дальше</a>";
		}
	} else {
		if(s>59){
			m=Math.floor(s/60);
			s=s-m*60;
		}
        if(m>59){
        	h=Math.floor(m/60);
        	m=m-h*60;
        }
        if(s<10){
        	s="0"+s;
        }
        if(m<10){
        	m="0"+m;
        }
        
       	bxx.innerHTML=h+":"+m+":"+s;
	}    
	if (timeout == 1) {
    	window.setTimeout("t_fix();", 100);
    }
    }
}
//-->
</script>

<br/>
Fixed t() timer:<br/>

<div id="bxx2"></div>

<script language=JavaScript>
	pp2=seconds_left;
    t_fix();
</script>


</body>

</html>